package com.study.modules.saas.repository.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.study.modules.saas.repository.model.OrderDO;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderDao extends BaseMapper<OrderDO> {

    @Select("select o.* from `order` o join bill b on o.order_id = b.order_id ")
    @Results({@Result(property = "id", column = "id"),
            @Result(property = "authUuid", column = "auth_uuid"),
            @Result(property = "storeUuid",column = "store_uuid"),
            @Result(property = "orderId",column = "order_id"),
            @Result(property = "accountUuid",column = "account_uuid"),
            @Result(property = "contactUuid",column = "contact_uuid"),
            @Result(property = "assignedTo",column = "assigned_to"),
            @Result(property = "bills", column = "order_id", javaType = List.class,
                    many = @Many(select = "com.study.modules.repository.dao.BillDao.selectBillsByOrderId"))})
    List<OrderDO> selectOrder();

    @Select("select * from `order` where order_id = #{orderId}")
    OrderDO selectUserByOrderId(String orderId);

}
